package model;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Transient;
@Entity
@Table(name="positions")
public class Position extends BaseEntity{

	private static final long serialVersionUID = 1L;
	private User creator;
	private int totalPlaces;
	private String name;
	private String project;
	private String requirements;
	private Department department;
	private String responsibilities;
	private boolean active;
	private List<Candidate> candidates;
	private List<Candidate> acceptedCandidates=new ArrayList<Candidate>();
	private List<Comment> comments;
	private boolean approved;

	public Position() {

	}

	public Position(User creator, int totalPlaces, String name, String project,
			String requirements, Department department, String responsibilities,
			List<Candidate> candidates, List<Candidate> acceptedCandidates,
			List<Comment> comments, boolean active, boolean approved) {
		super();
		this.creator = creator;
		this.totalPlaces = totalPlaces;
		this.name = name;
		this.project = project;
		this.requirements = requirements;
		this.department = department;
		this.responsibilities = responsibilities;
		this.candidates = candidates;
		this.comments = comments;
		this.active = active;
		this.approved = approved;
	}
	
	public Position(String name2, int totalPlaces, String project2, String requirments,
			Department department2, String responsibilities2) {
		this.name = name2;
		this.totalPlaces = totalPlaces;
		this.project = project2;
		this.requirements = requirments;
		this.department = department2;
		this.responsibilities = responsibilities2;
	}

	@OneToOne 
	@JoinColumn (name="id_user")
	public User getCreator() {
		return creator;
	}
	
	@Column(name = "approved")
	public boolean isApproved() {
		return approved;
	}

	public void setApproved(boolean approved) {
		this.approved = approved;
	}

	@Column(name = "active")
	public boolean isActive() {
		return active;
	}

	public void setActive(boolean active) {
		this.active = active;
	}
	
	public void setCreator(User creator) {
		this.creator = creator;
	}

	@Column(name="total_places")
	public int getTotalPlaces() {
		return totalPlaces;
	}

	public void setTotalPlaces(int totalPlaces) {
		this.totalPlaces = totalPlaces;
	}

	@Column(name="name")
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@Column(name="project")
	public String getProject() {
		return project;
	}

	public void setProject(String project) {
		this.project = project;
	}

	@Column(name="requirements")
	public String getRequirements() {
		return requirements;
	}

	public void setRequirements(String requirements) {
		this.requirements = requirements;
	}

	@OneToOne
	@JoinColumn (name="id_department")
	public Department getDepartment() {
		return department;
	}

	public void setDepartment(Department department) {
		this.department = department;
	}

	@Column(name="responsibilities")
	public String getResponsibilities() {
		return responsibilities;
	}

	public void setResponsibilities(String responsibilities) {
		this.responsibilities = responsibilities;
	}

	@ManyToMany 
	@JoinTable(name="positioncandidate", joinColumns={@JoinColumn(name="id_position")}, inverseJoinColumns={@JoinColumn(name="id_candidate")})
	public List<Candidate> getCandidates() {
		return candidates;
	}

	public void setCandidates(List<Candidate> candidates) {
		this.candidates = candidates;
	}
	
    @Transient
	public List<Candidate> getAcceptedCandidates() {
		return acceptedCandidates;
	}

	public void setAcceptedCandidates(List<Candidate> acceptedCandidates) {
		this.acceptedCandidates = acceptedCandidates;
	}

	@ManyToMany 
	@JoinTable(name="positioncomment", joinColumns={@JoinColumn(name="id_position")}, inverseJoinColumns={@JoinColumn(name="id_comment")})
	public List<Comment> getComments() {
		return comments;
	}

	public void setComments(List<Comment> comments) {
		this.comments = comments;
	}

}
